package com.kb.erp.entity.quote;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
@Data
public class    ResponseElement {
    @JsonProperty("code")
    private int code;
    @JsonProperty("msg")
    private String msg;
    @JsonProperty("products")
    private List<Product> products;


    //乘以1.13
    public void adjustPricesForInflation() {
        if (products != null) {
            for (Product product : products) {
                if (product.getPrices() != null) {
                    for (Product.Price price : product.getPrices()) {
                        // Adjust the cost
                        BigDecimal adjustedCost = price.getCost().multiply(BigDecimal.valueOf(1.13));
                        price.setCost(adjustedCost);
                    }
                }
                if (product.getStdPrices() != null) {
                    for (Product.Price price : product.getStdPrices()) {
                        // Adjust the cost
                        BigDecimal adjustedCost = price.getCost().multiply(BigDecimal.valueOf(1.13));
                        price.setPrice(adjustedCost);
                    }
                }
            }
        }
    }


    // Getters and Setters
    @JsonIgnoreProperties(ignoreUnknown = true)
    @Data
    public static class Product {
        @JsonProperty("sku")
        private String sku;
        @JsonProperty("displayName")
        private String displayName;
        @JsonProperty("productStatus")
        private String productStatus;
        @JsonProperty("rohsStatusCode")
        private String rohsStatusCode;
        @JsonProperty("packSize")
        private int packSize;
        @JsonProperty("unitOfMeasure")
        private String unitOfMeasure;
        @JsonProperty("id")
        private String id;


        @JsonProperty("prices")
        private List<Price> prices;

        @JsonProperty("std_prices")
        private List<Price> stdPrices;


        @JsonProperty("attributes")
        private List<Attr> attrs;


        @JsonProperty("inv")
        private int inv;
        @JsonProperty("vendorId")
        private String vendorId;
        @JsonProperty("vendorName")
        private String vendorName;
        @JsonProperty("brandName")
        private String brandName;
        @JsonProperty("translatedManufacturerPartNumber")
        private String translatedManufacturerPartNumber;
        @JsonProperty("translatedMinimumOrderQuality")
        private int translatedMinimumOrderQuality;

        @JsonProperty("stock")
        private Stock stock;
        @JsonProperty("countryOfOrigin")
        private String countryOfOrigin;
        @JsonProperty("comingSoon")
        private boolean comingSoon;
        @JsonProperty("inventoryCode")
        private int inventoryCode;
        @JsonProperty("nationalClassCode")
        private String nationalClassCode;
        @JsonProperty("publishingModule")
        private String publishingModule;
        @JsonProperty("releaseStatusCode")
        private int releaseStatusCode;
        @JsonProperty("isSpecialOrder")
        private boolean isSpecialOrder;
        @JsonProperty("isAwaitingRelease")
        private boolean isAwaitingRelease;
        @JsonProperty("reeling")
        private boolean reeling;
        @JsonProperty("discountReason")
        private int discountReason;
        @JsonProperty("brandId")
        private String brandId;

        // Getters and Setters

        @Data
        public static class Price {
            @JsonProperty("to")
            private int to;
            @JsonProperty("from")
            private int from;
            @JsonProperty("cost")
            private BigDecimal cost;

            private BigDecimal price;
            // Getters and Setters

            public BigDecimal calculatePrice() {
                return this.cost.divide(BigDecimal.valueOf(0.9), 4, RoundingMode.HALF_UP);
            }
        }


        @Data
        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class  Attr {
            @JsonProperty("attributeLabel")
            private String attributeLabel;
            @JsonProperty("attributeValue")
            private String attributeValue;
        }

        @Data

        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class Stock {
            @JsonProperty("level")
            private int level;
        }
    }
}